package com.flute.framework.search.result.xmlresult;

/**
 * 节点属性封装类
 * 
 * @author xuweiwei
 * 
 */
public class Attribute {
	/**
	 * 属性名
	 */
	private String name;
	/**
	 * 属性值
	 */
	private String content;
	/**
	 * 包含属性的节点
	 */
	private Node node;

	public Attribute(String name) {
		setName(name);
	}

	public Attribute(String name, String content) {
		this(name);
		setContent(content);
	}

	public Attribute(String name, Node node) {
		this(name);
		setNode(node);
	}

	public Attribute(String name, String content, Node node) {
		this(name, content);
		setNode(node);
	}

	@Override
	public int hashCode() {
		return name.hashCode() + content.hashCode() + node.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return Boolean.FALSE;
		}
		if (this == obj) {
			return Boolean.TRUE;
		}
		if (!(obj instanceof Attribute)) {
			return Boolean.FALSE;
		}
		Attribute a = (Attribute) obj;

		return (getNode() != null && getName() != null
				&& getNode().equals(a.getNode()) && getName().equals(
				a.getName()));
	}

	@Override
	public String toString() {
		StringBuilder result = new StringBuilder();
		if (getName() != null) {
			result.append(getName());
			result.append("=\"");
			if (getContent() != null) {
				result.append(XmlParserUtil.filter(getContent()));
			}
			result.append("\"");
		}

		return result.toString();
	}

	public void setName(String name) {
		this.name = name.trim();
	}

	public Node getNode() {
		return node;
	}

	public void setNode(Node node) {
		this.node = node;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getName() {
		return name;
	}
}
